/*
 * Copyright 2010
 * Jairou Software Organization
 * All Rights Reserved.
 * 
 * This software is the proprietary 
 * information of Roger Ramia
 * and the Jairou Software Organization 
 * Use is subject to license terms.
 * 
 * For licensing information please visit
 * http://www.jairou.org/license
 * 
 * @author Roger Ramia
 */
package org.jairou.web;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.jairou.core.XML;

public class XLSServlet
extends HttpServlet {
	
	/**
	 * serial version id
	 */
	private static final long serialVersionUID = -8419183542219790382L;
	
	
	public void doGet(HttpServletRequest req, HttpServletResponse resp) 
	throws ServletException {
		this.doPost(req, resp);
	}
	
	/**
	 * still under development
	 */
	public void doPost(HttpServletRequest req, HttpServletResponse resp) 
	throws ServletException {
		try {
			System.out.println("XLS here...");
			if (Web.isDefined(req)) {
				String id = Web.getId(req);
				String template = XML.get("request."+id+".template");
				if (template != null) {
					resp.setContentType("application/xls");
					req.getRequestDispatcher(template).include(req, resp);
				}
			}
			else resp.sendError(404);
		}
		catch(Exception e) {
			throw new ServletException(e);
		}
	}
}